<template>
  <div class="home-konwledges">
    
    <knowledge-search
      :sKnowledge="kList"
      @handleSearch="handleSearch"
    ></knowledge-search>
    
    <knowledge :cknowledges="knowledges"></knowledge>
    <pagination
      @item-click="pageClick"
      :cUrl="url"
      :cTotal="total"
      :cPageSize="pageSize"
    ></pagination>
  </div>
</template>

<script>
import { selectKnowledgesPage } from "../api/knowledge";
import Knowledge from "../components/Knowledge.vue";
import KnowledgeSearch from "../components/KnowledgeSearch.vue";
import Pagination from "../components/Pagination.vue";
import Purchase from "../components/Purchase.vue";
export default {
  data() {
    return {
      knowledges: [],
      input: "",
      total: 0,
      pageSize: 10,
      searchValue: "",
      kList:[],
      url: "/knowledge/",
      knowledgesCount: sessionStorage.getItem("/knowledge/pageCode")
        ? sessionStorage.getItem("/knowledge/pageCode")
        : 1,
    };
  },
  created() {
    this.$store.commit("updateActiveIndex", "4");
    this.getData()
  },
  methods: {
    pageClick(item) {
      this.knowledges = item;
    },
    handleSearch(val) {
      this.searchValue = val;
      this.getData();
    },
    getData() {
      selectKnowledgesPage({
        pageNum: this.knowledgesCount,
        keys:this.searchValue
      }).then((res) => {
        if (res.flag == true) {
          let tmp = res.data.list;
          tmp.forEach((e) => {
            const flieArr = e.picPath.split(".");
            e.type = flieArr[flieArr.length - 1];
          });
          this.knowledges = tmp;
          this.total = res.data.total;
        }
      });
    },
  },
  components: { Knowledge, Pagination, Purchase, KnowledgeSearch },
};
</script>

<style>
</style>